package com.ar4j.type;

import java.sql.Types;
import java.util.Date;

/**
 * Converter class able to convert instances of DateWithoutMillis to Date objects and back as needed.
 */
public class DateWithoutMillisTypeConverter implements ITypeConverter<DateWithoutMillis, Date> {

  @Override
  public Date convertToStorage(DateWithoutMillis value) {
    return (value == null ? null : value.getDate());
  }

  @Override
  public DateWithoutMillis convertFromStorage(Date storageValue) {
    return (storageValue == null ? null : new DateWithoutMillis(storageValue.getTime()));
  }

  @Override
  public int getSqlType() {
    return Types.TIMESTAMP;
  }
  
  @Override
  public Class<DateWithoutMillis> getObjectType() {
    return DateWithoutMillis.class;
  }

  @Override
  public Class<Date> getStorageType() {
    return Date.class;
  }

  @Override
  public void setTypes(Class<DateWithoutMillis> objectType, Class<Date> storageType) {
    throw new UnsupportedOperationException(("Cannot execute setTypes on DateWithoutMillisTypeConverter, it is not needed"));
  }

}
